package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.RiskDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Risk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = RiskService.class)
@Transactional
public class RiskServiceImpl implements RiskService {

    @Autowired
    private RiskDao riskDao;

    //风险评估查询
    public PageResult findPage(QueryPageBean queryPageBean) {
        //mybatis分页查询工具
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage, pageSize);
        //mybaits提供
        Page<Risk> page = riskDao.findByCondition(queryString);

        long total = page.getTotal();
        List<Risk> rows = page.getResult();

        return new PageResult(total, rows);
    }

    //新增风险评估
    public void add(Risk risk) {
        riskDao.add(risk);
    }

    //风险评估编辑表单回显
    public Risk findById(Integer id) {

        return riskDao.findById(id);

    }

    //风险评估删除
    public void delete(Integer id) {
        riskDao.delete(id);
    }

    //风险评估编辑提交存储
    public void edit(Risk risk) {
        riskDao.edit(risk);
    }
}
